# coding=utf-8

import random
import string
import time


# 处理21点游戏相关
class Game21:

    def __init__(self):
        self.nums = []
        self.time = 0
        self.winner = ("", 0, 0)
        self.players = []
        self.is_begin = False

    # 生成四个数字，
    # 再次调用该函数将生成不同数字，所以，不要多次调用
    def problem(self):
        self.nums = []
        for x in range(4):
            self.nums.append(random.randint(1, 10))
        self.nums.sort()
        return self.nums

    # 开始游戏
    def begin(self):
        self.winner = ("", 0, 0)
        self.time = time.time()
        self.is_begin = True
        self.players = []

    # 结束游戏
    def end(self):
        self.winner = ("", 0, 0)
        self.is_begin = False
        self.players = []
        self.nums = []

    def is_played(self, player_name):
        return player_name in self.players

    # 返回值：得分、赢家（元组）、是否结束游戏、是否更新最高分、是否已提交过答案
    def play_game(self, player_name, expression):
        try:
            score = self._calc_score(expression)
        except:
            raise
        else:
            tm = time.time() - self.time
            is_end = False
            is_better = False
            is_played = player_name in self.players
            # 第一次提交才能进入胜者相关的判断
            if not is_played:
                is_end = score == 21 and tm < 15
                self.players.append(player_name)
                is_better = self._update_winner(player_name, score, tm)
            return score, self.winner, is_end, is_better, is_played

    # 更新赢家
    def _update_winner(self, player_name, score, tm):
        # 后调用该函数时间必然靠后，没有比较时间的必要
        if score > self.winner[1]:
            self.winner = (player_name, score, tm)
            return True
        else:
            return False

    def get_winner(self):
        return self.winner

    # 检查表达式是否仅有合法符号与数字组成
    def _check(self, line):
        # 排除乘方运算
        if line.find("**") >= 0:
            raise Exception("Input error, illegal operator **.")
        str_num = ""
        str_nums = []
        # 用合法分隔符将表达式分割
        separator = "+-*/() "
        for ch in line:
            if ch in separator:
                if str_num:
                    str_nums.append(str_num)
                    str_num = ""
            else:
                str_num += ch
        if str_num:
            str_nums.append(str_num)
        # 检查是否为纯整数
        nums = []
        for str_num in str_nums:
            for ch in str_num:
                if ch not in string.digits:
                    raise Exception("Input error, illegal operator %s." % ch)
            nums.append(int(str_num))
        # 排序并检查是否与原数字相同
        nums.sort()
        if nums != self.nums:
            raise Exception("Input error, wrong numbers.")

    # 若表达式合法，计算分数
    def _calc_score(self, line):
        try:
            self._check(line)
            score = eval(line)
        except Exception, e:
            raise e
        if score > 21:
            score = 21 - score
        return score

# 测试
if __name__ == "__main__":
    game21 = Game21()
    game21.problem()
    while True:
        expr = raw_input()
        try:
            output = game21.play_game("ddd", expr)
        except Exception, e:
            print e
        else:
            print output[0]
